package com.jason.rxjavatest;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.jakewharton.rxbinding.view.RxView;

import java.util.concurrent.TimeUnit;

import rx.Subscriber;
import rx.functions.Action1;

/**
 * @Author: Jason
 * @Date: 16/1/4
 * @Time: 16:50
 */

public class RxViewActivity extends AppCompatActivity implements View.OnClickListener {

    private Button bt;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_rxview);


        bt = (Button) findViewById(R.id.bt_tomain);

        bt.setOnClickListener(this);




        RxView.clicks(bt)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe();



    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_tomain:
                Log.e("button", "button点击了");
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Intent intent = new Intent(RxViewActivity.this, MainActivity.class);
                        startActivity(intent);

                    }
                }, 4000);


                break;

        }
    }
}
